package model.sqlite;

import model.DAOFactory;
import model.TypeOperationDAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Classe de gestion de la couche persistance des données pour une base de donnees SQLite
 * @author Francis
 * @version 1.0
 */

public class SqliteDAOFactory extends DAOFactory
{
	private static final String DBURL="jdbc:sqlite:../../data/comptes.db";
	private static Connection conn;
	  
	/**
	 * Constructeur
	 */
	public SqliteDAOFactory()
	{
		  if (conn == null)
		  {  
			  try
			  {
				  Class.forName("org.sqlite.JDBC");
				  conn = DriverManager.getConnection(DBURL);
			  } 
			  catch (Exception e)
			  {
				  System.err.println( e.getClass().getName() + ": " + e.getMessage() );
			  }
			  
		  }		  
	}
	
	
	public TypeOperationDAO getTypeOperation()
	{
		return new SqliteTypeOperationDAO(conn);
	}
	
	public void close()
	{
		try
		{
			conn.close();
		}
		catch (SQLException e)
		{
			System.err.println( e.getClass().getName() + ": " + e.getMessage() );
		}
	}

}
